package com.alipay;

import com.alipay.config.AlipayClientFactory;
import com.alipay.config.AlipayConfig;
import com.alipay.model.request.*;
import com.alipay.model.response.*;
import com.alipay.service.impl.*;

/**
 * @author lwj
 * @create 2025-10-10-16:27
 *
 * 支付宝支付模板类，对外统一调用入口
 */
public class AlipayTemplate {
    /**
     * 小程序支付服务
     */
    private final MiniAppPayServiceImpl miniAppPayService;
    /**
     * PC网页支付服务
     */
    private final PcPayServiceImpl pcPayService;
    /**
     * 扫码支付服务
     */
    private final ScanPayServiceImpl scanPayService;
    /**
     * 手机网站支付服务
     */
    private final WapPayServiceImpl wapPayService;
    /**
     * 退款服务
     */
    private final RefundServiceImpl refundService;

    public AlipayTemplate(AlipayConfig config) {
        AlipayClientFactory alipayClientFactory = new AlipayClientFactory(config);
        this.miniAppPayService = new MiniAppPayServiceImpl(alipayClientFactory.createClient(), config);
        this.pcPayService = new PcPayServiceImpl(alipayClientFactory.createClient(), config);
        this.scanPayService = new ScanPayServiceImpl(alipayClientFactory.createClient(), config);
        this.wapPayService = new WapPayServiceImpl(alipayClientFactory.createClient(), config);
        this.refundService = new RefundServiceImpl(alipayClientFactory.createClient(), config);
    }

    /**
     * 小程序支付
     * @param request 小程序支付请求
     * @return 小程序支付响应
     */
    public MiniAppPayResponse miniAppPay(MiniAppPayRequest request) {
        return miniAppPayService.pay(request);
    }

    /**
     * PC网页支付
     * @param request PC网页支付请求
     * @return PC网页支付响应
     */
    public PcPayResponse pcPay(PcPayRequest request) {
        return pcPayService.pay(request);
    }

    /**
     * 扫码支付
     * @param request 扫码支付请求
     * @return 扫码支付响应
     */
    public ScanPayResponse scanPay(ScanPayRequest request) {
        return scanPayService.pay(request);
    }

    /**
     * 手机网站支付
     * @param request 手机网站支付请求
     * @return 手机网站支付响应
     */
    public WapPayResponse wapPay(WapPayRequest request) {
        return wapPayService.pay(request);
    }

    /**
     * 退款
     * @param request 退款请求
     * @return 退款响应
     */
    public RefundResponse refund(RefundRequest request) {
        return refundService.pay(request);
    }
}
